package com.duolaibei.business.view.goods.mode;

import com.duolaibei.business.view.App;
import com.duolaibei.business.view.goods.greendao.DaoSession;
import com.duolaibei.business.view.goods.greendao.FormatsBeanDao;
import com.duolaibei.business.view.goods.greendao.GoodsBeanDao;

import java.util.ArrayList;
import java.util.List;

public class FormatsBeanManager {
    private static FormatsBeanManager instance;
    FormatsBeanDao formatsBeanDao;
    DaoSession daoSession;

    private FormatsBeanManager() {
        formatsBeanDao = App.getApp().getDaoSession().getFormatsBeanDao();
        daoSession = App.getApp().getDaoSession();
    }

    public static FormatsBeanManager getInstance() {
        if (instance == null) {
            synchronized (FormatsBeanManager.class) {
                if (instance == null) {
                    instance = new FormatsBeanManager();
                }
            }
        }
        return instance;
    }

    //增加
    public void addFormats(FormatsBean testBean) {
        formatsBeanDao.insert(testBean);
    }

    //删除
    public void deleteFormats(FormatsBean testBean) {
        formatsBeanDao.delete(testBean);
    }

    //修改
    public void updateFormats(FormatsBean testBean) {
        formatsBeanDao.update(testBean);
    }

    //条件查询
    public List selectAllFormats() {
        formatsBeanDao.detachAll();//清除缓存
        List list1 = formatsBeanDao.queryBuilder().build().list();
        return list1 == null ? new ArrayList() : list1;
    }

    //删除表中内容
    public void deleteAllFormat() {
        formatsBeanDao.deleteAll();
    }
}
